package xyz.kongbai121.demo;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import xyz.kongbai121.demo.util.OverImagesDeleteUtil;

import java.util.Timer;
import java.util.TimerTask;


@SpringBootApplication
@MapperScan(basePackages = "xyz.kongbai121.demo.mapper")
@EnableCaching
public class DemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(DemoApplication.class, args);

        new Thread(()->{
                Timer timer = new Timer();
                timer.scheduleAtFixedRate(new TimerTask() {
                    public void run() {
                        OverImagesDeleteUtil.resetOverNum();
                        System.out.println(OverImagesDeleteUtil.imagesDelete( "overImages"));
                    }
                }, 0, 1000 * 60 * 60 * 24);
        }).start();
    }
    // 分页查询
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;
    }
}
